home *** CD-ROM | disk | FTP | other *** search
/ Aminet 12 / Aminet 12 (1996)(GTI - Schatztruhe)[!][Jun 1996].iso / Aminet / misc / edu / Calgor.lha / Cal / CalSource / allanim.c next >
Encoding:
C/C++ Source or Header  |  1996-03-22  |  18.9 KB  |  656 lines

  1. /* Copyright © 1995-1996 : David Atkinson */
  2. /* V1.21 Allanim.c */
  3. /* Calgor */
  4.  
  5. #include<hold/extra.h>
  6. #include<hold/data.h>
  7.  
  8. #include<stdio.h>
  9. #include<stdlib.h>
  10. #include<string.h>
  11. #include<ctype.h>
  12.  
  13. #include<exec/types.h>
  14.  
  15. #include<graphics/rastport.h>
  16. #include<graphics/sprite.h>
  17.  
  18. #include<clib/dos_protos.h>
  19.  
  20. #ifdef(V3)
  21. #endif
  22.  
  23. typedef struct Rastport * RASTPTR;
  24. typedef struct SimpleSprite * SSPTR;
  25.  
  26. char txtstring[ARGLEN];
  27.  
  28. int ordersum[ARGNUM];
  29. VARBUILD argument[ARGNUM];
  30.  
  31. extern void alert(char *);
  32. extern void clean_local(void);
  33. extern void forward_move(MAPDEM [],MAPDEM,MAPDEM,SSPTR);
  34. extern void backward_move(MAPDEM [],MAPDEM,MAPDEM,SSPTR);
  35. extern void change_col(short);
  36. extern void chill(int);
  37.  
  38. extern __aligned __chip struct SimpleSprite pulse_sprite;
  39. extern __aligned __chip struct SimpleSprite cart_sprite;
  40. extern PLAN array_map[FUNCMAX][MEMMAX];
  41. extern PLAN dis_map[LEVEL][MAXACROSS];
  42. extern PLAN ic_map[FUNCMAX][VARMAX];
  43. extern FUNC func_index[FUNCMAX];
  44. extern int fnum;
  45. extern int raynum;
  46. extern int types;
  47. extern int dtype;
  48. extern SHORT squeek[2];
  49. extern SHORT fraction;
  50. extern BOOL keypress;
  51. extern BOOL lmbpress;
  52. extern UBYTE *keybufptr;
  53. void whatisit(char *);
  54. void clean_args(void);
  55. void al_clean(void);
  56. void plan_clear(PLAN);
  57. void itochar(int, char []);
  58. char check_index(char *);
  59. PLAN lookup_ray(char *,int);
  60. PLAN lookup_var(char *);
  61. PLAN get_splan(int);
  62. void get_road(PLAN);
  63. int prec(char anop);
  64. int putback(char *,int ,VALUE);
  65. SHORT anim_button(void);
  66. SHORT menu_buutton(void);
  67.  
  68. PLAN rec;
  69. int realindex=0;
  70.  
  71. MAPDEM pathone[9] = { {290,24,START_U},{290,19,ALEFT},{270,19,ADOWN},
  72.                          {270,73,ALEFT},{260,73,FIN_D},{260,80,TERMINAL},
  73.                          {260,73,ALEFT},{68,73,FIN_D},{68,80,TERMINAL}
  74.                     };
  75.  
  76. MAPDEM pathtwo[4] = { {602,190,START_D},{602,236,ALEFT},{0,0,TERMINAL},
  77.                       {38,236,TERMINAL}
  78.                     };
  79.  
  80. MAPDEM paththree[7] = { {602,190,START_D},{602,236,ALEFT},{0,0,TERMINAL},
  81.                         {0,0,TERMINAL},{0,0,TERMINAL},
  82.                         {68,236,FIN_U},{68,190,TERMINAL}
  83.                       };
  84.  
  85.  
  86. MAPDEM pathfour[3] = { {CARTX,CARTY,START_D},{0,0,FIN_R},{0,0,TERMINAL} };
  87.  
  88. MAPDEM pathfive[3] = { {38,236,ARIGHT},{68,236,FIN_U},{68,190,TERMINAL} };
  89.  
  90. MAPDEM backone[4] = { {68,190,START_D},{68,236,TERMINAL},{0,0,TERMINAL},
  91.                      {0,0,TERMINAL}
  92.                    };
  93.  
  94. char index[MAXILEN];
  95. char oldname[MAXILEN];
  96.  
  97. void al_clean(){
  98. int k;
  99.    for(k=0;k<ARGNUM;k++){
  100.      if(argument[k].tname!=NULL)
  101.        free(argument[k].tname);
  102.      if(argument[k].dexrep!=NULL)
  103.        free(argument[k].dexrep);
  104.    }
  105.    clean_args();
  106. }
  107.  
  108.  
  109. void plan_clear(PLAN aplan){
  110.    aplan.worth.number = 0;
  111.    aplan.p_name = NULL;
  112.    aplan.points.x=0;
  113.    aplan.points.y=0;
  114.    aplan.points.way=TERMINAL;
  115.    aplan.eol.x=0;
  116.    aplan.eol.y=0;
  117.    aplan.eol.way=TERMINAL;
  118. }
  119.  
  120. void clean_args(){
  121. int i;
  122.  
  123.    for(i=0;i<ARGNUM;i++){
  124.      argument[i].sign[0] = '\0';
  125.      argument[i].sign[1] = '\0';
  126.      argument[i].sign[2] = '\0';
  127.      argument[i].tname = NULL;
  128.      argument[i].dexrep = NULL;
  129.    }
  130. }
  131.  
  132.  
  133. /* Everytime whatisit is called it mallocs memory, therefore make sure memory is
  134.    freed from system before we malloc another lot. Values are nulled in
  135.    control.c via clean_args */
  136.  
  137. void whatisit(char *thing){
  138.  
  139. char cpar;
  140. BOOL hit;
  141. int foo,over,measure,arnum;
  142.  
  143.    arnum=over=0;
  144.    al_clean();
  145.    cpar = *(thing + over);
  146.    while( (cpar!='\0') && (arnum<ARGNUM) && (over<ARGLEN) ){
  147.      hit=TRUE;
  148.      foo=0;
  149.      while( (isalpha( (UBYTE) cpar )) || (cpar =='_') ) {
  150.        txtstring[foo]=cpar;
  151.        foo++;
  152.        over++;
  153.        cpar = *(thing+over);
  154.      }
  155.      if (foo>0){
  156.        argument[arnum].tname=malloc(sizeof(char) * foo);
  157.        if(argument[arnum].tname==NULL){
  158.          clean_local();
  159.          alert("Failed To Allocate Memory (A) (whatisit)\n");
  160.        }
  161.        for(measure=0;measure<foo;measure++){
  162.          *( (argument[arnum].tname) + measure) = txtstring[measure];
  163.        }
  164.        *(argument[arnum].tname + measure) = '\0';
  165.      }
  166.      else{
  167.        argument[arnum].tname = NULL;
  168.      }
  169.      while( ((cpar = *(thing+over))!='\0') && (over<ARGLEN) && (hit==TRUE) ){
  170.        switch(cpar){
  171.          case '0' : case '1': case '2': case '3': case '4': case '5':
  172.          case '6': case '7' : case '8' : case '9' :
  173.             if(argument[arnum].dexrep!=NULL){
  174.                clean_local();
  175.                alert("Error in intrep \n");
  176.             }
  177.             foo=0;
  178.             do {
  179.                  txtstring[foo]=cpar;
  180.                  foo++;
  181.                  over++;
  182.                  cpar=*(thing+over);
  183.                }
  184.             while( isdigit( (UBYTE) cpar) );
  185.             argument[arnum].dexrep=malloc(sizeof(char) * foo);
  186.             if(argument[arnum].dexrep==NULL){
  187.               clean_local();
  188.               alert("Failed To Allocate Memory (B) (whatisit)\n");
  189.             }
  190.             for(measure=0;measure<foo;measure++){
  191.               *(argument[arnum].dexrep + measure) = txtstring[measure];
  192.             }
  193.             *(argument[arnum].dexrep + measure) = '\0';
  194.             break;
  195.          case '[' :
  196.            if(argument[arnum].dexrep!=NULL){
  197.                 clean_local();
  198.                 alert("Error in index (whatisit)\n");
  199.            }
  200.            foo=0;
  201.            over++;
  202.            while( (cpar=*(thing+over)) != ']'){
  203.              txtstring[foo]=cpar;
  204.              foo++;
  205.              over++;
  206.            }
  207.            argument[arnum].dexrep=malloc(sizeof(char) * foo);
  208.            if(argument[arnum].dexrep==NULL){
  209.              clean_local();
  210.              alert("Failed To Allocate Memory (C) (whatisit)\n");
  211.            }
  212.            for(measure=0;measure<foo;measure++){
  213.              *(argument[arnum].dexrep + measure) = txtstring[measure];
  214.            }
  215.            *(argument[arnum].dexrep + measure) = '\0';
  216.            over++;
  217.            break;
  218.          case '+' : case '-' : case '*' : case '/' :
  219.            argument[arnum].sign[0] = cpar;
  220.            over++;
  221.            arnum++;
  222.            hit=FALSE;
  223.            cpar=*(thing+over);
  224.            while( isspace((UBYTE) cpar) ){
  225.              over++;
  226.              cpar = *(thing+over);
  227.            }
  228.            break;
  229.          case '<' : case '>' : case '=' : case '!' :
  230.            argument[arnum].sign[0] = cpar;
  231.            over++;
  232.            if (*(thing+over)== '='){
  233.              argument[arnum].sign[1] = *(thing+over);
  234.              over++;
  235.            }
  236.            arnum++;
  237.            hit=FALSE;
  238.            cpar=*(thing+over);
  239.            while( isspace((UBYTE) cpar) ){
  240.              over++;
  241.              cpar = *(thing+over);
  242.            }
  243.            break;
  244.          default :
  245.            if(isspace( (UBYTE) cpar) != 0){
  246.              while( isspace((UBYTE) cpar) ){
  247.                over++;
  248.                cpar = *(thing+over);
  249.              }
  250.            }
  251.            else{
  252.              printf("Unknown Token: %c\n",cpar);
  253.              clean_local();
  254.              alert("Did not recognise TOKEN (Whatisit)\n");
  255.            }
  256.            break;
  257.        }
  258.      }
  259.    }
  260. }
  261.  
  262. /* Check_index Goes through the function array, checking the expected
  263.    name with the function name, returning the function index.  Check
  264.    for NULL as strcmp doesn't like to be given them */
  265.  
  266. char check_index(char *title){
  267. int q;
  268. char times = 'A';
  269.    for(q=0;q<FUNCMAX;q++){
  270.      if((func_index[q].f_label!=NULL) && (title!=NULL)){
  271.        if ( strcmp(func_index[q].f_label,title) == 0 )
  272.          ++times;
  273.      }
  274.    }
  275.        return times;
  276. }
  277.  
  278. PLAN lookup_ray(char *target,int con){
  279.  
  280.    plan_clear(rec);
  281.    if((array_map[raynum][con].p_name!=NULL) && (target!=NULL) ){
  282.      if( strcmp(array_map[raynum][con].p_name,target) == 0 ){
  283.        if( (raynum>= ARRAYMAX) || (con>=MAXACROSS) ){  /* Should be con>=MEMMAX in V1.21 */
  284.          clean_local();
  285.          alert("Exceeded Limits (lookup_ray)\n");
  286.        }
  287.        rec = dis_map[raynum][con];
  288.        rec.p_name=array_map[raynum][con].p_name; /* Get Name */
  289.        rec.worth.number=array_map[raynum][con].worth.number;  /* Get Value */
  290.      }
  291.    }
  292.    return rec;
  293. }
  294.  
  295. PLAN lookup_var(char *target){
  296. int m;
  297.  
  298.    plan_clear(rec);
  299.    for(m=0;m<VARMAX;m++){
  300.      if( (target!=NULL) && (ic_map[fnum][m].p_name!=NULL)){
  301.        if(strcmp(target,ic_map[fnum][m].p_name) == 0 )
  302.           rec=ic_map[fnum][m];
  303.      }
  304.    }
  305.    return rec;
  306. }
  307.  
  308. int putback(char *prop,int post,VALUE part){
  309. int err=0;
  310. int r;
  311.  
  312.    if( (prop!=NULL) && (array_map[raynum][post].p_name!=NULL) ){
  313.      if(strcmp(prop,array_map[raynum][post].p_name)==0){
  314.        array_map[raynum][post].worth.number=part.number;
  315.        err=1;
  316.      }
  317.    }
  318.    for(r=0;r<VARMAX;r++){
  319.      if( (prop!=NULL) && (ic_map[fnum][r].p_name!=NULL) ){
  320.        if(strcmp(prop,ic_map[fnum][r].p_name)==0){
  321.          ic_map[fnum][r].worth.number=part.number;
  322.          err=1;
  323.        }
  324.      }
  325.    }
  326.    if(err==0)
  327.      printf("Prop:%s\nP_name:%s\n",prop,array_map[raynum][post].p_name);
  328.    return err;
  329. }
  330.  
  331.  
  332. void itochar(int subject, char hold[])
  333. {
  334. int calc,newnum,element,neg;
  335.  
  336.    neg=element=calc=newnum=0;
  337.    if(subject<0){
  338.      hold[0]='-';
  339.      element++;
  340.      neg=1;
  341.    }
  342.    newnum=abs(subject);
  343.    do {
  344.       newnum /= 10;
  345.       element++;
  346.       } while(newnum>0);
  347.  
  348.    if (element <=OBVAR ){
  349.      hold[element]='\0';
  350.      newnum=abs(subject);
  351.      element--;
  352.      while(element >= neg){
  353.        calc = newnum % 10;
  354.        newnum /= 10;
  355.        hold[element] = (char) (calc+48);
  356.        element--;
  357.      }
  358.   }
  359.   else{
  360.     hold[0]='-';
  361.     hold[1]='\0';
  362.   }
  363. }
  364.  
  365. /* PLAN get_splan takes an integer which is the index to the VARBUILD argument
  366.    array and returns coordinates of the evaluted expression.
  367.    Get_splan evaluates integers, integer variables, array with integer index,
  368.    array with variable index but only to the first level. A quick fix has been made
  369.    so array index with integer offset is now possible.  Due to this fix the argument
  370.    array may be altered, so whatisit will have to be called to restantiate
  371.    the argument array */
  372.  
  373. PLAN get_splan(int jump){
  374. int sheep;
  375. int contents;
  376. BOOL set=TRUE;
  377.  
  378.    plan_clear(rec);
  379.    if (argument[jump].tname==NULL){
  380.      /*  String is a number */
  381.      /*  For version V1.21 take a look at negative sign and assign value here */
  382.      /*  At the moment if this was done, get 1-(-1) giving incorrect answer */
  383.      rec.p_name="absolute";
  384.      if(argument[jump].dexrep!=NULL)
  385.         rec.worth.number=atoi(argument[jump].dexrep);
  386.      else
  387.         rec.worth.number = 0;
  388.      rec.points.x=68;
  389.      rec.points.y=236;
  390.      rec.points.way=FIN_U;
  391.      rec.eol.x=68;
  392.      rec.eol.y=190;
  393.      rec.eol.way=TERMINAL;
  394.      types = ICABS;
  395.      realindex=0;
  396.    }
  397.    if( (argument[jump].tname!=NULL) && (argument[jump].dexrep!=NULL) ){
  398.      /* The string is an array */
  399.      for(sheep=0;sheep<strlen(argument[jump].dexrep);sheep++){
  400.        contents = (int) *(argument[jump].dexrep+sheep);
  401.        index[sheep] = *(argument[jump].dexrep+sheep);
  402.        if( isdigit((UBYTE)contents) == 0 ){
  403.          set=FALSE;
  404.        }
  405.      }
  406.      index[sheep] = '\0';
  407.      for(sheep=0;sheep<strlen(argument[jump].tname);sheep++){
  408.        oldname[sheep] = *(argument[jump].tname+sheep);
  409.      }
  410.      oldname[sheep] = '\0';
  411.  
  412.      if(set==TRUE){
  413.        /* the index is an absolute number */
  414.        realindex=atoi(argument[jump].dexrep);
  415.        rec=lookup_ray(argument[jump].tname,realindex);
  416.      }
  417.      else{
  418.        /* the index is a variable or variable with offset */
  419.        /* al_clean(); */
  420.        whatisit(index);
  421.        switch(argument[0].sign[0]){
  422.          case '\0' :
  423.            /* Index is variable */
  424.            rec=lookup_var(argument[0].tname);
  425.            realindex=rec.worth.number;
  426.            rec=lookup_ray(oldname,realindex);
  427.            break;
  428.          case '+' :
  429.            /* Index is varible with addition offset */
  430.            rec=lookup_var(argument[0].tname);
  431.            realindex=rec.worth.number+atoi(argument[1].dexrep);
  432.            rec=lookup_ray(oldname,realindex);
  433.            break;
  434.          case '-' :
  435.            /* Index is variable with negative offset */
  436.            rec=lookup_var(argument[0].tname);
  437.            realindex=rec.worth.number - atoi(argument[1].dexrep);
  438.            rec=lookup_ray(oldname,realindex);
  439.            break;
  440.          case '*' :
  441.            /* Index is variable with product offset */
  442.            rec=lookup_var(argument[0].tname);
  443.            realindex=rec.worth.number * atoi(argument[1].dexrep);
  444.            rec=lookup_ray(oldname,realindex);
  445.            break;
  446.          case '/' :
  447.            /* Index is variable with divide offset */
  448.            rec=lookup_var(argument[0].tname);
  449.            realindex=rec.worth.number / atoi(argument[1].dexrep);
  450.            rec=lookup_ray(oldname,realindex);
  451.            break;
  452.          default :
  453.            clean_local();
  454.            alert("Sign not recognised (get_splan)\n");
  455.            break;
  456.        }
  457.      }
  458.      if(rec.p_name==NULL){
  459.        clean_local();
  460.        alert("Error in assigning index to array (get_splan)\n");
  461.      }
  462.      types=ICRAY;
  463.      al_clean();
  464.      return rec;
  465.    }
  466.    if( (argument[jump].tname!=NULL) && (argument[jump].dexrep==NULL) ){
  467.     /* String is a variable */
  468.      rec=lookup_var(argument[jump].tname);
  469.      if(rec.p_name==NULL){
  470.        clean_local();
  471.        alert("Error in assigning variable (get_splan)\n");
  472.      }
  473.      types=ICVAR;
  474.      realindex=0;
  475.    }
  476.    al_clean();
  477.    return rec;
  478. }
  479.  
  480. int prec(char anop){
  481. int pri;
  482.  
  483.    switch(anop){
  484.      case '/' :
  485.        pri=4;
  486.        break;
  487.      case '*' :
  488.        pri=3;
  489.        break;
  490.      case '+' :
  491.        pri=2;
  492.        break;
  493.      case '-' :
  494.        pri=1;
  495.        break;
  496.      case '\0' :
  497.        pri=0;
  498.        break;
  499.      default :
  500.        clean_local();
  501.        alert("Ilegal sign in sum (prec)\n");
  502.        break;
  503.    }
  504.    return pri;
  505. }
  506.  
  507. void get_road(PLAN route){
  508.  
  509.    change_col( (short) GET);
  510.    switch(types){
  511.      case ICVAR :
  512.        paththree[2]=route.points;
  513.        paththree[2].way=ADOWN;
  514.        paththree[3]=route.eol;
  515.        paththree[3].way = AUP;
  516.        paththree[4]=route.points;
  517.        paththree[4].way=ALEFT;
  518.        forward_move(paththree,paththree[0],paththree[6],&pulse_sprite);
  519.        break;
  520.      case ICRAY :
  521.        pathtwo[2].x=68;
  522.        pathtwo[2].y=236;
  523.        pathtwo[2].way=FIN_L;
  524.        pathtwo[3].x=38;
  525.        pathtwo[3].y=236;
  526.        pathtwo[3].way=TERMINAL;
  527.        pathfour[1]=route.points;
  528.        pathfour[2]=route.eol;
  529.        forward_move(pathtwo,pathtwo[0],pathtwo[3],&pulse_sprite);
  530.        forward_move(pathfour,pathfour[0],pathfour[2],&cart_sprite);
  531.        chill(STILL/fraction);
  532.        backward_move(pathfour,pathfour[2],pathfour[0],&cart_sprite);
  533.        forward_move(pathfive,pathfive[0],pathfive[2],&pulse_sprite);
  534.        break;
  535.      case ICABS :
  536.        pathtwo[2]=route.points;
  537.        pathtwo[3]=route.eol;
  538.        forward_move(pathtwo,pathtwo[0],pathtwo[3],&pulse_sprite);
  539.        break;
  540.      default :
  541.        clean_local();
  542.        alert("ERROR In (get_road)\n");
  543.        break;
  544.   }
  545. }
  546.  
  547. /* anim_button examines the coordinates from the mouse handler and returns
  548.    the according button value */
  549.  
  550. SHORT anim_button(void){
  551.     if(lmbpress==TRUE){
  552.       if ( (squeek[0] >= Kstop.min.xc) && (squeek[0] <= Kstop.max.xc) &&
  553.            (squeek[1] >= Kstop.min.yc) && (squeek[1] <= Kstop.max.yc) )
  554.            return STOPBUT;
  555.       if ( (squeek[0] >= Kplay.min.xc) && (squeek[0] <= Kplay.max.xc) &&
  556.            (squeek[1] >= Kplay.min.yc) && (squeek[1] <= Kplay.max.yc) )
  557.            return PLAYBUT;
  558.       if ( (squeek[0] >= Keject.min.xc) && (squeek[0] <= Keject.max.xc) &&
  559.            (squeek[1] >= Keject.min.yc) && (squeek[1] <= Keject.max.yc) )
  560.            return EJECTBUT;
  561.       if ( (squeek[0] >= Kpause.min.xc) && (squeek[0] <= Kpause.max.xc) &&
  562.            (squeek[1] >= Kpause.min.yc) && (squeek[1] <= Kpause.max.yc) )
  563.            return PAUSEBUT;
  564.       if ( (squeek[0] >= Kinfo.min.xc) && (squeek[0] <= Kinfo.max.xc) &&
  565.            (squeek[1] >= Kinfo.min.yc) && (squeek[1] <= Kinfo.max.yc) )
  566.            return INFOBUT;
  567.       if ( (squeek[0] >= Kffor.min.xc) && (squeek[0] <= Kffor.max.xc) &&
  568.            (squeek[1] >= Kffor.min.yc) && (squeek[1] <= Kffor.max.yc) )
  569.            return FFORBUT;
  570.     }
  571.     if(keypress==TRUE){
  572.       if(keybufptr!=NULL){
  573.         if ( *(keybufptr+0)==0x31 )
  574.           return NUM1KEY;
  575.         if ( *(keybufptr+0)==0x32 )
  576.           return NUM2KEY;
  577.         if ( *(keybufptr+0)==0x33 )
  578.           return NUM3KEY;
  579.         if ( *(keybufptr+0)==0x34 )
  580.           return NUM4KEY;
  581.         if ( *(keybufptr+0)==0x35 )
  582.           return NUM5KEY;
  583.         if(  *(keybufptr+0)==0x1B )
  584.           return ESCKEY;
  585.       }
  586.     }
  587.     return NOBUT;
  588. }
  589.  
  590. SHORT menu_button(void){
  591.  
  592.   if(lmbpress==TRUE){
  593.     if ( (squeek[0] > Kf1.min.xc) && (squeek[0] < Kf1.max.xc) &&
  594.          (squeek[1] > Kf1.min.yc) && (squeek[1] < Kf1.max.yc) )
  595.          return F1BUTTON;
  596.     if ( (squeek[0] > Kf2.min.xc) && (squeek[0] < Kf2.max.xc) &&
  597.          (squeek[1] > Kf2.min.yc) && (squeek[1] < Kf2.max.yc) )
  598.          return F2BUTTON;
  599.     if ( (squeek[0] > Kf3.min.xc) && (squeek[0] < Kf3.max.xc) &&
  600.          (squeek[1] > Kf3.min.yc) && (squeek[1] < Kf3.max.yc) )
  601.          return F3BUTTON;
  602.     if ( (squeek[0] > Kf4.min.xc) && (squeek[0] < Kf4.max.xc) &&
  603.          (squeek[1] > Kf4.min.yc) && (squeek[1] < Kf4.max.yc) )
  604.          return F4BUTTON;
  605.     if ( (squeek[0] > Kf5.min.xc) && (squeek[0] < Kf5.max.xc) &&
  606.          (squeek[1] > Kf5.min.yc) && (squeek[1] < Kf5.max.yc) )
  607.          return F5BUTTON;
  608.     if ( (squeek[0] > Kn1.min.xc) && (squeek[0] < Kn1.max.xc) &&
  609.          (squeek[1] > Kn1.min.yc) && (squeek[1] < Kn1.max.yc) )
  610.          return NUM1KEY;
  611.     if ( (squeek[0] > Kn2.min.xc) && (squeek[0] < Kn2.max.xc) &&
  612.          (squeek[1] > Kn2.min.yc) && (squeek[1] < Kn2.max.yc) )
  613.          return NUM2KEY;
  614.     if ( (squeek[0] > Kn3.min.xc) && (squeek[0] < Kn3.max.xc) &&
  615.          (squeek[1] > Kn3.min.yc) && (squeek[1] < Kn3.max.yc) )
  616.          return NUM3KEY;
  617.     if ( (squeek[0] > Kn4.min.xc) && (squeek[0] < Kn4.max.xc) &&
  618.          (squeek[1] > Kn4.min.yc) && (squeek[1] < Kn4.max.yc) )
  619.          return NUM4KEY;
  620.     if ( (squeek[0] > Kn5.min.xc) && (squeek[0] < Kn5.max.xc) &&
  621.          (squeek[1] > Kn5.min.yc) && (squeek[1] < Kn5.max.yc) )
  622.          return NUM5KEY;
  623.     if ( (squeek[0] > KES.min.xc) && (squeek[0] < KES.max.xc) &&
  624.          (squeek[1] > KES.min.yc) && (squeek[1] < KES.max.yc) )
  625.          return ESCKEY;
  626.   }
  627.   if(keypress==TRUE){
  628.     if(keybufptr!=NULL){
  629.       if ( (*(keybufptr+0)==0x9B) && (*(keybufptr+1)==0x30) && (*(keybufptr+2)==0x7e) )
  630.         return F1BUTTON;
  631.       if ( (*(keybufptr+0)==0x9B) && (*(keybufptr+1)==0x31) && (*(keybufptr+2)==0x7e) )
  632.         return F2BUTTON;
  633.       if ( (*(keybufptr+0)==0x9B) && (*(keybufptr+1)==0x32) && (*(keybufptr+2)==0x7e) )
  634.         return F3BUTTON;
  635.       if ( (*(keybufptr+0)==0x9B) && (*(keybufptr+1)==0x33) && (*(keybufptr+2)==0x7e) )
  636.         return F4BUTTON;
  637.       if ( (*(keybufptr+0)==0x9B) && (*(keybufptr+1)==0x34) && (*(keybufptr+2)==0x7e) )
  638.         return F5BUTTON;
  639.       if ( *(keybufptr+0)==0x31 )
  640.         return NUM1KEY;
  641.       if ( *(keybufptr+0)==0x32 )
  642.         return NUM2KEY;
  643.       if ( *(keybufptr+0)==0x33 )
  644.         return NUM3KEY;
  645.       if ( *(keybufptr+0)==0x34 )
  646.         return NUM4KEY;
  647.       if ( *(keybufptr+0)==0x35 )
  648.         return NUM5KEY;
  649.       if(  *(keybufptr+0)==0x1B )
  650.         return ESCKEY;
  651.     }
  652.   }
  653.   return NOBUT;
  654. }
  655.  
  656.